/**
 *  Copyright (C) 2021 Huawei Device Co., Ltd.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package at.favre.lib.hwcpipedemo.slice;

import at.favre.lib.hwcpipedemo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Text;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class MainAbilitySlice extends AbilitySlice {

    private static final String TAG = "HWCPipe";

    // Load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("sample");
    }

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_layout_main_slice);
        Button textGetCpu = (Button) findComponentById(ResourceTable.Id_text_get_cpu);
        Button textGetGpu = (Button) findComponentById(ResourceTable.Id_text_get_gpu);
        Button textCreateFromJson = (Button) findComponentById(ResourceTable.Id_text_create_from_json);
        Button textCreateFromPart = (Button) findComponentById(ResourceTable.Id_text_create_from_part);
        Button textEnableCpu = (Button) findComponentById(ResourceTable.Id_text_enable_cpu);
        Button textEnableGpu = (Button) findComponentById(ResourceTable.Id_text_enable_gpu);

        Text text_info = (Text) findComponentById(ResourceTable.Id_text_info);

        textGetGpu.setClickedListener(component -> {
                    HiLog.info(new HiLogLabel(HiLog.LOG_APP, 0, TAG), "java：getGpuInfoFromJni");
                    text_info.setText(getGpuInfoFromJni());
                }
        );
        textGetCpu.setClickedListener(component -> {
                    HiLog.info(new HiLogLabel(HiLog.LOG_APP, 0, TAG), "java：getCpuInfoFromJni");
                    text_info.setText(getCpuInfoFromJni());
                }
        );
        textCreateFromJson.setClickedListener(component -> {
            HiLog.info(new HiLogLabel(HiLog.LOG_APP, 0, TAG), "java：createHWCPipeFromJson");
            text_info.setText(createHWCPipeFromJson());
        });
        textCreateFromPart.setClickedListener(component -> {
            HiLog.info(new HiLogLabel(HiLog.LOG_APP, 0, TAG), "java：createHWCPipePart");
            text_info.setText(createHWCPipePart());
        });
        textEnableCpu.setClickedListener(component -> {
            HiLog.info(new HiLogLabel(HiLog.LOG_APP, 0, TAG), "java：enableCpuCounter");
            text_info.setText(enableCpuCounter());
        });
        textEnableGpu.setClickedListener(component -> {
            HiLog.info(new HiLogLabel(HiLog.LOG_APP, 0, TAG), "java：enableGpuCounter");
            text_info.setText(enableGpuCounter());
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();

    public static native String getGpuInfoFromJni();

    public static native String getCpuInfoFromJni();

    public static native String createHWCPipeFromJson();

    public static native String createHWCPipePart();

    public static native String enableCpuCounter();

    public static native String enableGpuCounter();
}
